package com.tanhua.server.controller;

import com.tanhua.domain.db.PageResult;
import com.tanhua.domain.vo.FriendVo;
import com.tanhua.domain.vo.UserLikeNum;
import com.tanhua.server.service.UserLikeNumService;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserLikeNumController {

    @Autowired
    private UserLikeNumService userLikeNumService;

    /**
     * 互相喜欢，喜欢，粉丝 - 统计
     */
    @GetMapping("/counts")
    public ResponseEntity countTheNumberOfLikes() {
        //a.调用service 返回UserLikeNum对象
       UserLikeNum userLikeNum= userLikeNumService.countTheNumberOfLikes();
        //b.返回状态码
        return ResponseEntity.ok(userLikeNum);
    }

    /**
     * 互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
     */
    @GetMapping("/friends/{type}")
    public ResponseEntity findPageUserLikeNum(@PathVariable("type") Integer type,
                                              @RequestParam(defaultValue = "1")Integer page,
                                              @RequestParam(defaultValue = "10")Integer pagesize) {
        //a.调用service 传入type、page、pagesize 返回pageResult<FriendVo>
        PageResult<FriendVo> pageResult = userLikeNumService.findPageUserLikeNum(type,page,pagesize);
        //b.返回状态码
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 粉丝 - 喜欢
     */
    @PostMapping("/fans/{uid}")
    public ResponseEntity becomeFriendsWithFans(@PathVariable("uid") Long FansId) {
        //a.调用service层 传入粉丝的Id
        userLikeNumService.becomeFriendsWithFans(FansId);
        //b.返回状态码
        return ResponseEntity.ok(null);
    }



}
